# 集合的创建
s = set()
print(s, type(s))
s = {1, 2, 3, 4, 5, 6, 7}
print(s, type(s))
# 类型转换
s1 = set([21, 23, 35, 93])  # list-->set
print(s1)
s2 = set((83, 30, 93, 38))  # tuple-->set
print(s2)
s3 = set('123')  # str-->set
print(s3)  # 字典是无需的，排列的顺序也是随机的
s4 = set({'name': 'mia', 'score': 98, 'age': 19})  #dict-->set
print(s4)  # 输出的只是键
# in
print(1 in s)
# len
print(len(s))
print(min(s))
print(max({23, 53, 13, 1, 43, 14}))
# del s
# print(s)

# 集合的遍历
print("-" * 50)
for i in s:
    print(i, end=" ")
print()
# 常用方法
s.remove(2)  # 删除特定元素
print(s)
s.update({223, 43, 83, 923})
print(s)
s.add(45)
print(s)
s.add(1)
print(s)

# 交集  并集
s5 = {5, 6, 7, 8, 9, 10, 11}
print(s & s5)  # 交集
print(s | s5)  # 并集
# 列表去重
score = [80, 70, 60, 80, 70, 60, 40]
s = set(score)
print(s)
d = {}
# 统计各个分数都有的学生
for i in s:
    t = score.count(i)  # 通过集合来去重，计算列表中元素个数
    d[i] = t  # 用分数作为索引值
for k, v in d.items():
    print("得分为%d的学生有%d人" % (k, v))
